<%@page import="java.util.Map"%>
<%@page import="cts.com.dbmanager.DepositWithdrawlCash"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<style type="text/css">
#tableCSS
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:50%;
border-color:blue;
}
#tableCSS td, #tableCSS th 
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
}

#tableCSS td 
{
font-size:1.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#E3CEF6;
}
#tableCSS tr.alt td 
{
color:#000000;
background-color:#EAF2D3;
}
</style>
<script>
	function callPayNow() {
		var xmlhttp;
		var txtAcNo = document.getElementById("txtAcNo").value;
		var transDesc = document.getElementById("txtTransDescription").value;
		var txtBeneficiaryAcNo = document.getElementById("txtBeneficiaryAcNo").value;
		var amt = document.getElementById("txtAmt").value;
		alert(txtAcNo+" "+txtBeneficiaryAcNo+" "+transDesc+" "+amt);
		if (txtAcNo.length == 0 && txtBeneficiaryAcNo.length == 0 && amt.length==0) {
			document.getElementById("txtHint").innerHTML = "";
			return;
		}
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
				if(xmlhttp.responseText.search("Available Balance:")!=-1){
					var indexOfAvailBal=xmlhttp.responseText.indexOf("Available Balance:");
					var lengthOfAvailBal="Available Balance:".length;
					document.getElementById("currentBal").innerHTML=xmlhttp.responseText.substr(indexOfAvailBal+lengthOfAvailBal,xmlhttp.responseText.length);
				}
			}
		}

		xmlhttp.open("POST", "availableBalance.do", true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		
		
		xmlhttp.send("txtAcNo=" + txtAcNo + "&txtBeneficiaryAcNo="
				+ txtBeneficiaryAcNo + "&txtTransDescription="
				+ transDesc + "&txtAmt=" + amt
				+ "&operation=withdraw&transferType=sameBankTransfer");
	}
</script>

</head>
<body>
	<center>
		<h1>Transfer in other Cognizant Bank A/c</h1>
		<br/>
		<table id="tableCSS">
			<tr>
				<td>*From Account No.:</td>
				<td><input type="text" id="txtAcNo" name="txtAcNo" value="12345"/>
				<b id="currentBal"><%=new DepositWithdrawlCash().getAvailableBalance("12345") %></b>
				</td>
			</tr>
			<tr id="alt">
				<td>*To Account No.:</td>
				<td>
					<select id="txtBeneficiaryAcNo">
						<%
							DepositWithdrawlCash dCash = new DepositWithdrawlCash();
							String columnNames = "b.Beneficiary_Ac_No +':'+b.Beneficiary_Name+':'+b.Beneficiary_IFSC+':'+Beneficiary_Bank ";
							String tableNames = "AccountInformation a,BENEFICIARY_ACCOUNT b";
							String condition = " where a.Account_Id=b.Primary_Account_Id and a.Bank_Name=b.Beneficiary_Bank and a.Account_Id='12345'";
							Map<Integer, String[]> map = dCash.getDataFromTablesUsingCondition(
									columnNames, tableNames, condition);
							for (String[] str : map.values()) {
						%>
							<%
								for (String s : str) {
								String[] columns=s.split(":");
								
							%>

							<option value="<%=columns[0]%>"><%=columns[0]+" - "+columns[1]%></option>
							<%
								}
							%>
						<%
							}
						%>
				</select></td>
			</tr>
			<tr>
				<td>Description</td>
				<td><input type="text" id="txtTransDescription" />
				</td>
			</tr>
			<tr>
				<td>Enter Amount</td>
				<td><input type="text" id="txtAmt" />
				</td>
			</tr>
			<tr>
				<td><a style="color: blue;" href="#" onclick="callPayLater()">Pay Later</a></td>
				<td><a style="color: blue;" href="#" onclick="callPayNow()">Pay Now</a></td>
			</tr>
			<tr>
				<td colspan="2"><div id="txtHint"></div>
				</td>
			</tr>
		</table>
		<a href="index.jsp" style="color: blue;" >Back</a>
	</center>
</body>
</html>